package com.niuniu.rushdorm.mapper;

import com.niuniu.rushdorm.pojo.entity.GroupsUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GroupsUserMapper {
    GroupsUser selectByUid(long uid);

    int insert(GroupsUser groupsUser);

    @Select("select count(*) from groups_user where group_id = #{teamId} and is_del = 0")
    int selectMembers(int teamId);

    @Select("select uid from groups_user where group_id = #{teamId} and is_del = 0")
    List<Long> selectByGroupId(int teamId);

    @Update("update groups_user set is_del = 1 where group_id = #{teamId} and is_del = 0")
    int deleteGroup(int teamId);

    @Update("update groups_user set is_del = 1 ,  leave_time = #{leaveTime} where id = #{id} and is_del = 0")
    int leaveGroup(GroupsUser groupsUser);

    @Select("select uid from groups_user where is_creator = 1 and group_id = #{teamId} and is_del = 0")
    long getCreatorUid(int teamId);

    @Update("update groups_user set is_creator = #{isCreator} and id = #{id}")
    int setCreator(GroupsUser groupsUser);


}
